#!/usr/bin/env python3
# -*-coding:utf-8-*-
# author:link
import sqlite3
from config.db_config import *

class ConnectSql():
    def __init__(self):
        self.con=sqlite3.connect(sqlite_path,check_same_thread = False)
        self.cur=self.con.cursor()
    #查询一条数据
    def select_one(self,id):
        self.cur.execute('select * from caselist_copy where id=?',[id])
        rdata=self.cur.fetchall()
        return rdata
    #查询全部数据
    def select_all(self):
        self.cur.execute('select * from caselist_copy')
        rdata=self.cur.fetchall()
        return rdata
    # 查询指定接口的所有值
    def select_module(self,module):
        self.cur.execute('select * from caselist_copy where module=?',[module])
        rdata=self.cur.fetchall()
        return rdata
    #查询预期结果的值
    def select_expected(self,id):
        self.cur.execute('select expectedresult from caselist_copy where id=?',[id])
        rdata=self.cur.fetchone()
        return rdata
    #查询实际结果的值
    def select_actual(self,id):
        self.cur.execute('select actualresult from caselist_copy where id=?',[id])
        rdata=self.cur.fetchone()
        return rdata
    def select_passed(self,id):
        self.cur.execute('select passed from caselist_copy where id=?',[id])
        rdata=self.cur.fetchone()
        return rdata
    def insert(self,value):
        self.cur.execute('INSERT INTO caselist_copy(passed) VALUES (?)',[value])
        self.con.commit()
    def updata_actual(self,value,id):
        self.cur.execute('update caselist_copy set actualresult=? where id=?',[value,id])
        self.con.commit()
    def updata_passed(self,value,id):
        self.cur.execute('update caselist_copy set passed=? where id=?',[value,id])
        self.con.commit()
    def updata_isrun(self,value,module):
        self.cur.execute('update caselist_copy set isrun=? where module=?',[value,module])
        self.con.commit()
    def updata_runtime(self,value,id):
        self.cur.execute('update caselist_copy set runtime=? where id=?',[value,id])
        self.con.commit()
    def delete(self,id):
        self.cur.execute('delete from caselist_copy where id=?',[id])
        self.con.commit()
    def close(self):
        self.con.close()




